Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 8 - Handlers / Using Subroutines


Types of Subroutines

There are two types of subroutines: those with labeled parameters and those with positional parameters.

For example, the following statement calls a subroutine with positional parameters.

minimumValue(150, 4000)
The following statement calls a subroutine with labeled parameters. The direct parameter is the list of filenames. The labeled parameters are identified by the labels stringToFind and checkCase.

findFiles of {"March Expenses", "April Expenses", ÿ   "May Expenses", "June Expenses"} given ÿ   stringToFind:"LeChateau", checkCase:false
The definition for a subroutine determines what kind of parameters the subroutine requires. When you call a subroutine, you must list its parameters in the same way they are specified in the subroutine definition.

You can also have subroutines with no parameters. To indicate that a subroutine has no parameters, you must include a pair of empty parentheses after the subroutine name in both the subroutine definition and the subroutine call. For example, the following script shows the definition and subroutine call for a subroutine called helloWorld that has no parameters.

on helloWorld()
   display dialog "Hello World"end

helloWorld()

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996